<?php
declare (strict_types = 1);

namespace app\master\controller;

use app\BaseController;
use app\common\service\OrderService\OrderReturnService;
use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;
use app\common\service\GoodsService\SyncGoodsService;
use app\common\service\ConsulService\ConsulClientProvider;
use app\common\service\ChannelBusinessService\BusinessService;

/**
 * @Group("SyncApi")
 * @Middleware({AppRequestMiddleware::class})
 */
class SyncApi extends BaseController
{
    /**
     * 接收云仓推送的商品
     * @Route("receiveGoods/:cid",method="POST")
     * @return string
     */
    public function receiveGoods($cid)
    {
        $data=$this->request->post();
        $data['cid']=(int)$cid;
        $result = callApi(SyncGoodsService::class, 'getGoodsIntoMq',$data);
        return json($result);
    }
    
      
    /**
     * 调用hyperf接口demo
     * @Route("addChannelDemo",method="GET")
     * @return string
     */
    public function addChannelDemo( BusinessService $service,BusinessService $BusinessService)
    {
        
        $json = '{"cid":"4","level":"3","skucode":["2208221720089873","2208221720090615"]}';
        $data = json_decode($json,true);
        
        $res = $BusinessService->businessLevelGoodsChoose($data);
        
        
        print_r($res);die;
        $res = $service->channelBusiness($data);
        print_r($res);die;

        //服务发现
        $bbcAdminServices = ConsulClientProvider::instance()->getAgentHealthTcpServices('bbcAdminServices');
        print_r($bbcAdminServices);die;
        //调用微服务接口数据demo
        $start = microtime(true);
        $args = [
            'mobile'   => '15228257231',
        ];
        $res = callTcpService('bbcUserAccountRegister',$args);
        echo "used time " . bcsub((string)microtime(true),(string)$start,3);
        print_r($res);die;
    }

    /**
     * 接收云仓推送的商品
     * @Route("returnMoney",method="POST")
     * @return string
     */
    public function returnMoney()
    {
        $data=$this->request->post();
        $result = callApi(OrderReturnService::class, 'returnMoney',$data);
        return apiResponse($result);
    }
}